package com.ets.cert.model;

import com.ets.cert.model.BaseObject;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableComponent;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import javax.xml.bind.annotation.XmlRootElement;

import java.io.Serializable;

@Entity
@Table(name="news",catalog="cert")
@Searchable
@XmlRootElement
public class News extends BaseObject implements Serializable {
    private Long id;
    private String content;
    private Date date;
    private String title;
    private Long hits;

    @Id @GeneratedValue(strategy=IDENTITY) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @Column(name="content")
    @SearchableProperty
    public String getContent() {
        return this.content;
    }
    
    public void setContent(String content) {
        this.content = content;
    }
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="date", length=19)
    @SearchableProperty
    public Date getDate() {
        return this.date;
    }
    
    public void setDate(Date date) {
        this.date = date;
    }
    
    @Column(name="title")
    @SearchableProperty
    public String getTitle() {
        return this.title;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
    
    @Column(name="hits")
    @SearchableProperty
    public Long getHits() {
        return this.hits;
    }
    
    public void setHits(Long hits) {
        this.hits = hits;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        News pojo = (News) o;

        if (content != null ? !content.equals(pojo.content) : pojo.content != null) return false;
        if (date != null ? !date.equals(pojo.date) : pojo.date != null) return false;
        if (title != null ? !title.equals(pojo.title) : pojo.title != null) return false;
        if (hits != null ? !hits.equals(pojo.hits) : pojo.hits != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (content != null ? content.hashCode() : 0);
        result = 31 * result + (date != null ? date.hashCode() : 0);
        result = 31 * result + (title != null ? title.hashCode() : 0);
        result = 31 * result + (hits != null ? hits.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("content").append("='").append(getContent()).append("', ");
        sb.append("date").append("='").append(getDate()).append("', ");
        sb.append("title").append("='").append(getTitle()).append("', ");
        sb.append("hits").append("='").append(getHits()).append("'");
        sb.append("]");
      
        return sb.toString();
    }

}
